package com.fastwire.carriere.serviceorder.entity;

import java.util.Date;
import java.util.List;

import com.fastwire.carriere.common.util.DateUtil;
import com.fastwire.carriere.pegasus.vo.PegasusActivityDetailsVo;
import com.fastwire.carriere.pegasus.vo.PegasusNPPInfoVo;
import com.fastwire.carriere.pegasus.vo.PegasusOrderDetailsVo;
import com.fastwire.carriere.serviceorder.vo.ActivityVo;
import com.fastwire.carriere.serviceorder.vo.ProductInfoVo;
import com.fastwire.carriere.serviceorder.vo.ServiceOrderVo;
import com.google.common.collect.Lists;

// TODO: Auto-generated Javadoc
/**
 * The Class ServiceOrder.
 */
public class ServiceOrder {

	private long oid;
	private int version;
	private String workOrderNo;
	private String customerName;

	private Date customerReqDate;

	private String orderActionType;

	private String serviceType;

	private String workOrderType;

	private String priority;

	private String serviceActionType;

	private String orderStatus;
	private Date orderCreateDate;
	private Date orderCompleteDate;

	private String serviceId; // ext_id, service No

	private String projectId;

	private Date orderSubmitDate;

	private String newInstallAddrA;

	private String newInstallNameA;

	private String newExchangeCodeA;

	private String newInstallAddrB;

	private String newInstallNameB;

	private String newExchangeCodeB;

	private String existingInstallAddrA;

	private String existingInstallNameA;

	private String existingExchangeCodeA;

	private String existingInstallAddrB;

	private String existingInstallNameB;

	private String existingExchangeCodeB;

	private String installerName;

	private String lastUpdateId;

	private Date lastUpdateDate;

	private List<ProductInfo> productInfos;

	/** The activities. */
	private List<ServiceOrderActivity> activities;

	public ServiceOrder() {
		super();
	}

	public ServiceOrder(PegasusOrderDetailsVo orderVo) {
		super();

		this.workOrderNo = orderVo.getWorkOrderNo();
		this.customerName = orderVo.getCustomerName();
		this.customerReqDate = DateUtil.parseDate(DateUtil.DATE_SLASH,
				orderVo.getCustomerReqDate());
		this.orderActionType = orderVo.getOrderActionType();
		this.serviceType = orderVo.getServiceType();
		this.workOrderType = orderVo.getWorkOrderType();
		this.priority = orderVo.getPriority();
		this.serviceActionType = orderVo.getServiceActionType();
		this.orderStatus = orderVo.getOrderStatus();
		this.orderCreateDate = orderVo.getOrderCreateDate();
		this.orderCompleteDate = orderVo.getOrderCompleteDate();
		this.serviceId = orderVo.getServiceId();
		this.projectId = orderVo.getProjectId();
		this.orderSubmitDate = orderVo.getOrderSubmitDate();
		this.newInstallAddrA = orderVo.getNewInstallAddrA();
		this.newInstallNameA = orderVo.getNewInstallNameA();
		this.newExchangeCodeA = orderVo.getNewExchangeCodeA();
		this.newInstallAddrB = orderVo.getNewInstallAddrB();
		this.newInstallNameB = orderVo.getNewInstallNameB();
		this.newExchangeCodeB = orderVo.getNewExchangeCodeB();
		this.existingInstallAddrA = orderVo.getExistingInstallAddrA();
		this.existingInstallNameA = orderVo.getExistingInstallNameA();
		this.existingExchangeCodeA = orderVo.getExistingExchangeCodeA();
		this.existingInstallAddrB = orderVo.getExistingInstallAddrB();
		this.existingInstallNameB = orderVo.getExistingInstallNameB();
		this.existingExchangeCodeB = orderVo.getExistingExchangeCodeB();
		this.installerName = orderVo.getInstallerName();
		this.lastUpdateId = orderVo.getLastUpdateId();
		this.lastUpdateDate = orderVo.getLastUpdateDt();

		if (orderVo.getProductInfos() != null) {

			List<ProductInfo> productInfos = Lists.newArrayList();
			PegasusNPPInfoVo[] pegasusNPPInfoVos = orderVo.getProductInfos();
			for (int index = 0; index < pegasusNPPInfoVos.length; index++) {

				productInfos.add(new ProductInfo(pegasusNPPInfoVos[index]));
			}
			this.productInfos = productInfos;
		}

		if (orderVo.getActivities() != null) {

			List<ServiceOrderActivity> activities = Lists.newArrayList();
			PegasusActivityDetailsVo[] activityDetailsVos = orderVo
					.getActivities();
			for (int index = 0; index < activityDetailsVos.length; index++) {

				activities.add(new ServiceOrderActivity(
						activityDetailsVos[index]));
			}
			this.activities = activities;
		}
	}

	public ServiceOrder(ServiceOrderVo orderVo) {
		super();

		this.workOrderNo = orderVo.getWorkOrderNo();
		this.customerName = orderVo.getCustomerName();
		this.customerReqDate = orderVo.getCustomerReqDate();
		this.orderActionType = orderVo.getOrderActionType();
		this.serviceType = orderVo.getServiceType();
		this.workOrderType = orderVo.getWorkOrderType();
		this.priority = orderVo.getPriority();
		this.serviceActionType = orderVo.getServiceActionType();
		this.orderStatus = orderVo.getOrderStatus();
		this.orderCreateDate = orderVo.getOrderCreateDate();
		this.serviceId = orderVo.getServiceId();
		this.projectId = orderVo.getProjectId();
		this.orderSubmitDate = orderVo.getOrderSubmitDate();
		this.newInstallAddrA = orderVo.getNewInstallAddrA();
		this.newInstallNameA = orderVo.getNewInstallNameA();
		this.newExchangeCodeA = orderVo.getNewExchangeCodeA();
		this.newInstallAddrB = orderVo.getNewInstallAddrB();
		this.newInstallNameB = orderVo.getNewInstallNameB();
		this.newExchangeCodeB = orderVo.getNewExchangeCodeB();
		this.existingInstallAddrA = orderVo.getExistingInstallAddrA();
		this.existingInstallNameA = orderVo.getExistingInstallNameA();
		this.existingExchangeCodeA = orderVo.getExistingExchangeCodeA();
		this.existingInstallAddrB = orderVo.getExistingInstallAddrB();
		this.existingInstallNameB = orderVo.getExistingInstallNameB();
		this.existingExchangeCodeB = orderVo.getExistingExchangeCodeB();
		this.installerName = orderVo.getInstallerName();
		this.lastUpdateDate = DateUtil.getDate();

		if (orderVo.getProductInfos() != null) {

			List<ProductInfo> productInfos = Lists.newArrayList();
			List<ProductInfoVo> productInfoVos = orderVo.getProductInfos();
			for (ProductInfoVo productInfoVo : productInfoVos) {

				productInfos.add(new ProductInfo(productInfoVo));
			}
			this.productInfos = productInfos;
		}

		if (orderVo.getActivities() != null) {

			List<ServiceOrderActivity> activities = Lists.newArrayList();
			List<ActivityVo> activityVos = orderVo.getActivities();
			for (ActivityVo activityVo : activityVos) {

				activities.add(new ServiceOrderActivity(activityVo));
			}
			this.activities = activities;
		}
	}

	/**
	 * Adds the activity.
	 * 
	 * @param act
	 *            the act
	 */
	public void addActivity(ServiceOrderActivity act) {
		if (null == activities) {
			activities = Lists.newArrayList();
		}
		activities.add(act);
	}

	/**
	 * Adds the npp.
	 * 
	 * @param npp
	 *            the npp
	 */
	public void addNPP(ProductInfo npp) {
		if (null == productInfos) {
			productInfos = Lists.newArrayList();
		}
		productInfos.add(npp);
	}

	public long getOid() {
		return oid;
	}

	public void setOid(long oid) {
		this.oid = oid;
	}

	public int getVersion() {
		return version;
	}

	public void setVersion(int version) {
		this.version = version;
	}

	public String getWorkOrderNo() {
		return workOrderNo;
	}

	public void setWorkOrderNo(String workOrderNo) {
		this.workOrderNo = workOrderNo;
	}

	public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	public Date getCustomerReqDate() {
		return customerReqDate;
	}

	public void setCustomerReqDate(Date customerReqDate) {
		this.customerReqDate = customerReqDate;
	}

	public String getOrderActionType() {
		return orderActionType;
	}

	public void setOrderActionType(String orderActionType) {
		this.orderActionType = orderActionType;
	}

	public String getServiceType() {
		return serviceType;
	}

	public void setServiceType(String serviceType) {
		this.serviceType = serviceType;
	}

	public String getWorkOrderType() {
		return workOrderType;
	}

	public void setWorkOrderType(String workOrderType) {
		this.workOrderType = workOrderType;
	}

	public String getPriority() {
		return priority;
	}

	public void setPriority(String priority) {
		this.priority = priority;
	}

	public String getServiceActionType() {
		return serviceActionType;
	}

	public void setServiceActionType(String serviceActionType) {
		this.serviceActionType = serviceActionType;
	}

	public String getOrderStatus() {
		return orderStatus;
	}

	public void setOrderStatus(String orderStatus) {
		this.orderStatus = orderStatus;
	}

	public Date getOrderCreateDate() {
		return orderCreateDate;
	}

	public void setOrderCreateDate(Date orderCreateDate) {
		this.orderCreateDate = orderCreateDate;
	}

	public Date getOrderCompleteDate() {
		return orderCompleteDate;
	}

	public void setOrderCompleteDate(Date orderCompleteDate) {
		this.orderCompleteDate = orderCompleteDate;
	}

	public String getServiceId() {
		return serviceId;
	}

	public void setServiceId(String serviceId) {
		this.serviceId = serviceId;
	}

	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}

	public Date getOrderSubmitDate() {
		return orderSubmitDate;
	}

	public void setOrderSubmitDate(Date orderSubmitDate) {
		this.orderSubmitDate = orderSubmitDate;
	}

	public String getNewInstallAddrA() {
		return newInstallAddrA;
	}

	public void setNewInstallAddrA(String newInstallAddrA) {
		this.newInstallAddrA = newInstallAddrA;
	}

	public String getNewInstallNameA() {
		return newInstallNameA;
	}

	public void setNewInstallNameA(String newInstallNameA) {
		this.newInstallNameA = newInstallNameA;
	}

	public String getNewExchangeCodeA() {
		return newExchangeCodeA;
	}

	public void setNewExchangeCodeA(String newExchangeCodeA) {
		this.newExchangeCodeA = newExchangeCodeA;
	}

	public String getNewInstallAddrB() {
		return newInstallAddrB;
	}

	public void setNewInstallAddrB(String newInstallAddrB) {
		this.newInstallAddrB = newInstallAddrB;
	}

	public String getNewInstallNameB() {
		return newInstallNameB;
	}

	public void setNewInstallNameB(String newInstallNameB) {
		this.newInstallNameB = newInstallNameB;
	}

	public String getNewExchangeCodeB() {
		return newExchangeCodeB;
	}

	public void setNewExchangeCodeB(String newExchangeCodeB) {
		this.newExchangeCodeB = newExchangeCodeB;
	}

	public String getExistingInstallAddrA() {
		return existingInstallAddrA;
	}

	public void setExistingInstallAddrA(String existingInstallAddrA) {
		this.existingInstallAddrA = existingInstallAddrA;
	}

	public String getExistingInstallNameA() {
		return existingInstallNameA;
	}

	public void setExistingInstallNameA(String existingInstallNameA) {
		this.existingInstallNameA = existingInstallNameA;
	}

	public String getExistingExchangeCodeA() {
		return existingExchangeCodeA;
	}

	public void setExistingExchangeCodeA(String existingExchangeCodeA) {
		this.existingExchangeCodeA = existingExchangeCodeA;
	}

	public String getExistingInstallAddrB() {
		return existingInstallAddrB;
	}

	public void setExistingInstallAddrB(String existingInstallAddrB) {
		this.existingInstallAddrB = existingInstallAddrB;
	}

	public String getExistingInstallNameB() {
		return existingInstallNameB;
	}

	public void setExistingInstallNameB(String existingInstallNameB) {
		this.existingInstallNameB = existingInstallNameB;
	}

	public String getExistingExchangeCodeB() {
		return existingExchangeCodeB;
	}

	public void setExistingExchangeCodeB(String existingExchangeCodeB) {
		this.existingExchangeCodeB = existingExchangeCodeB;
	}

	public String getInstallerName() {
		return installerName;
	}

	public void setInstallerName(String installerName) {
		this.installerName = installerName;
	}

	public String getLastUpdateId() {
		return lastUpdateId;
	}

	public void setLastUpdateId(String lastUpdateId) {
		this.lastUpdateId = lastUpdateId;
	}

	public List<ProductInfo> getProductInfos() {
		return productInfos;
	}

	public void setProductInfos(List<ProductInfo> productInfos) {
		this.productInfos = productInfos;
	}

	public List<ServiceOrderActivity> getActivities() {
		return activities;
	}

	public void setActivities(List<ServiceOrderActivity> activities) {
		this.activities = activities;
	}

	public Date getLastUpdateDate() {
		return lastUpdateDate;
	}

	public void setLastUpdateDate(Date lastUpdateDate) {
		this.lastUpdateDate = lastUpdateDate;
	}

	public void update(ServiceOrderVo orderVo) {
		this.customerName = orderVo.getCustomerName();
		this.customerReqDate = orderVo.getCustomerReqDate();
		this.orderActionType = orderVo.getOrderActionType();
		this.serviceType = orderVo.getServiceType();
		this.workOrderType = orderVo.getWorkOrderType();
		this.priority = orderVo.getPriority();
		this.serviceActionType = orderVo.getServiceActionType();
		this.orderStatus = orderVo.getOrderStatus();
		this.orderCreateDate = orderVo.getOrderCreateDate();
		this.serviceId = orderVo.getServiceId();
		this.projectId = orderVo.getProjectId();
		this.orderSubmitDate = orderVo.getOrderSubmitDate();
		this.newInstallAddrA = orderVo.getNewInstallAddrA();
		this.newInstallNameA = orderVo.getNewInstallNameA();
		this.newExchangeCodeA = orderVo.getNewExchangeCodeA();
		this.newInstallAddrB = orderVo.getNewInstallAddrB();
		this.newInstallNameB = orderVo.getNewInstallNameB();
		this.newExchangeCodeB = orderVo.getNewExchangeCodeB();
		this.existingInstallAddrA = orderVo.getExistingInstallAddrA();
		this.existingInstallNameA = orderVo.getExistingInstallNameA();
		this.existingExchangeCodeA = orderVo.getExistingExchangeCodeA();
		this.existingInstallAddrB = orderVo.getExistingInstallAddrB();
		this.existingInstallNameB = orderVo.getExistingInstallNameB();
		this.existingExchangeCodeB = orderVo.getExistingExchangeCodeB();
		this.installerName = orderVo.getInstallerName();

		if (orderVo.getProductInfos() != null) {

			List<ProductInfo> productInfos = Lists.newArrayList();
			List<ProductInfoVo> productInfoVos = orderVo.getProductInfos();
			for (ProductInfoVo productInfoVo : productInfoVos) {

				productInfos.add(new ProductInfo(productInfoVo));
			}
			this.productInfos = productInfos;
		}

		if (orderVo.getActivities() != null) {

			List<ServiceOrderActivity> activities = Lists.newArrayList();
			List<ActivityVo> activityVos = orderVo.getActivities();
			for (ActivityVo activityVo : activityVos) {

				activities.add(new ServiceOrderActivity(activityVo));
			}
			this.activities = activities;
		}

		this.lastUpdateDate = DateUtil.getDate();

	}

	public void update(PegasusOrderDetailsVo orderVo) {
		this.customerName = orderVo.getCustomerName();
		this.customerReqDate = DateUtil.parseDate(DateUtil.DATE_SLASH,
				orderVo.getCustomerReqDate());
		this.orderActionType = orderVo.getOrderActionType();
		this.serviceType = orderVo.getServiceType();
		this.workOrderType = orderVo.getWorkOrderType();
		this.priority = orderVo.getPriority();
		this.serviceActionType = orderVo.getServiceActionType();
		this.orderStatus = orderVo.getOrderStatus();
		this.orderCreateDate = orderVo.getOrderCreateDate();
		this.orderCompleteDate = orderVo.getOrderCompleteDate();
		this.serviceId = orderVo.getServiceId();
		this.projectId = orderVo.getProjectId();
		this.orderSubmitDate = orderVo.getOrderSubmitDate();
		this.newInstallAddrA = orderVo.getNewInstallAddrA();
		this.newInstallNameA = orderVo.getNewInstallNameA();
		this.newExchangeCodeA = orderVo.getNewExchangeCodeA();
		this.newInstallAddrB = orderVo.getNewInstallAddrB();
		this.newInstallNameB = orderVo.getNewInstallNameB();
		this.newExchangeCodeB = orderVo.getNewExchangeCodeB();
		this.existingInstallAddrA = orderVo.getExistingInstallAddrA();
		this.existingInstallNameA = orderVo.getExistingInstallNameA();
		this.existingExchangeCodeA = orderVo.getExistingExchangeCodeA();
		this.existingInstallAddrB = orderVo.getExistingInstallAddrB();
		this.existingInstallNameB = orderVo.getExistingInstallNameB();
		this.existingExchangeCodeB = orderVo.getExistingExchangeCodeB();
		this.installerName = orderVo.getInstallerName();
		this.lastUpdateId = orderVo.getLastUpdateId();
		this.lastUpdateDate = orderVo.getLastUpdateDt();

		if (orderVo.getProductInfos() != null
				&& orderVo.getProductInfos().length > 0) {

			List<ProductInfo> productInfos = Lists.newArrayList();
			PegasusNPPInfoVo[] pegasusNPPInfoVos = orderVo.getProductInfos();
			for (int index = 0; index < pegasusNPPInfoVos.length; index++) {

				productInfos.add(new ProductInfo(pegasusNPPInfoVos[index]));
			}
			this.productInfos = productInfos;
		}

		if (orderVo.getActivities() != null) {

			List<ServiceOrderActivity> activities = Lists.newArrayList();
			PegasusActivityDetailsVo[] activityDetailsVos = orderVo
					.getActivities();
			for (int index = 0; index < activityDetailsVos.length; index++) {

				activities.add(new ServiceOrderActivity(
						activityDetailsVos[index]));
			}
			this.activities = activities;
		}

	}

	public String getPrdoductValue(String name) {

		String value = null;

		if (productInfos != null) {
			for (ProductInfo productInfo : productInfos) {
				//if (name.equals(productInfo.getParaName())) {    // modified by Jun on 20120408
			    if (name.equalsIgnoreCase(productInfo.getParaName())) {				    
					value = productInfo.getParaValue();
					break;
				}
			}
		}

		return value;

	}

}
